import 'package:dio/dio.dart';
import 'dart:convert';
import 'package:tuple/tuple.dart';
import 'String+extension.dart';
extension DioExtension on Response {
  Map<String,dynamic> toValue(){
    return this.toString().toMap();
  }
  Tuple4<Map<String,dynamic>,bool,int,String> toResult(){
    final Map<String,dynamic> j = toValue();
    int ret =  int.parse((j['code'] ?? "999").toString());
    String msg = (j['message'] ?? "数据异常").toString();
    bool success = ret == 200;
    if (!success){
      print("request:");
      print(this.request.uri.toString());
      print("body:");
      print((this.request.data as FormData).fields.map((e) => "\"${e.key}\":${e.value}").toList());
    }
    print("response:");
    print(this.toString());
    return Tuple4<Map<String,dynamic>,bool,int,String> (j,success, ret, msg);
  }
}